<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3, 4];
            console.log(arr.fill(4));
            console.log(arr); // [4, 4, 4, 4]
            arr.fill(5, 0, 2);
            console.log(arr); // [5, 5, 4, 4]
            console.dir(Array.prototype);
            Array.prototype.myFill = function (value, start = 0, end = this.length) {
                if (start && start < 0) start = this.length + start;
                if (end && end < 0) end = this.length + end;
                for (; start < end; start++) {
                    this[start] = value;
                }
                return this;
            };
            console.log(arr.fill(4));
            console.log(arr); // [4, 4, 4, 4]
            arr.fill(5, 0, 2);
            console.log(arr); // [5, 5, 4, 4]
        </script>
    </body>
</html>
